import store from '../store'
import {RouterMount,createRouter} from 'uni-simple-router';
import { isEmpty } from '../utils/utils.js'

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,  
	routes: [...ROUTES]
});

const whiteList = [
	'/pages/login',
	'/pages_base/common/form-page',
	'/pages/tabbar-item2',
	'/pages_teach/teach/teach-detail-page',
	'/pages_teach/teach/week-detail-page',
	'/pages_teach/teach/index',
	''
	
] // no redirect whitelist

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	// console.log(to.path);
	// console.log(store.state.user)
	console.log(to.path)
	console.log(whiteList.indexOf('nothing'))
	if (store.state.user.parentInfo != null){
		if (isEmpty(store.state.user.parentInfo.parentMobile)
			// && to.path != '/pages/login'
			// && to.path != '/pages_base/common/form-page'
			&& whiteList.indexOf(to.path) === -1
		) {
			next('/pages/login');
			return ;
		}
	}
	next();
});
// 全局路由后置守卫
router.afterEach((to, from) => {
    console.log('跳转结束')
})

export {
	router,
	RouterMount
}